package com.hyou.starter.autoconfigure.datasource.hikari;

import javax.sql.DataSource;

import com.zaxxer.hikari.HikariDataSource;

public class HikariDataSourceUtil {
    
    private HikariDataSourceUtil() {
        
    }
    
    /**
     * 构造Hikari数据源实例
     * 
     * @param dataSourceProp 数据源配置参数
     * @return 数据源对象
     */
    public static DataSource makeDataSource(HikariDataSourceProp dataSourceProp) {
        HikariDataSource dataSource = new HikariDataSource();
        dataSource.setDriverClassName(dataSourceProp.getDriverClassName());
        dataSource.setJdbcUrl(dataSourceProp.getJdbcUrl());
        dataSource.setUsername(dataSourceProp.getUsername());
        dataSource.setPassword(dataSourceProp.getPassword());
        dataSource.setConnectionTimeout(dataSourceProp.getConnectionTimeout());
        dataSource.setIdleTimeout(dataSourceProp.getIdleTimeout());
        dataSource.setMaxLifetime(dataSourceProp.getMaxLifetime());
        dataSource.setConnectionTestQuery(dataSourceProp.getConnectionTestQuery());
        dataSource.setMinimumIdle(dataSourceProp.getMinimumIdle());
        dataSource.setMaximumPoolSize(dataSourceProp.getMaximumPoolSize());
        return dataSource;
    }
    
}
